<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>layer的应用案例--表单校验</title>
    <!-- 1.引入layui.css样式表 -->
    <link href="layui/css/layui.css" rel="stylesheet">
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input id="username" type="text" name="username" lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input id="password" type="password" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<!-- 2.引入layui.js -->
<script src="layui/layui.js"></script>
<script type="text/javascript">
    layui.use(function (){
        var layer = layui.layer;
        var $ = layui.jquery;
        $("#username").blur(function (){
            let username = $("#username").val();
            if(username == null || username == "" || username.length == 0){
                layer.tips('用户名不能为空', '#username', {
                    tips: [3,'red']
                });
            }
        })


    })
</script>
</body>
</html>
